<?php

namespace app\admin\model;

use think\Model;

class Order extends Model {

    // 表名
    protected $name = 'order';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'pay_type_text',
        'status_text',
        'type_text',
    ];

    public function getStatusList() {
        return ['0' => __('待支付'), '1' => __('待补货'), '10' => __('已完成'), '20' => __('已取消')];
    }

    public function getTypeList() {
        return ['1' => __('普通订单'), '2' => __('付款补货'), '3' => __('边吃边付'), '10' => __('充值')];
    }

    public function getPayTypeList() {
        return ['1' => __('微信支付'), '2' => __('余额支付')];
    }

    public function getStatusTextAttr($value, $data) {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getPayTypeTextAttr($value, $data) {
        $value = $value ? $value : $data['pay_type'];
        $list = $this->getPayTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getTypeTextAttr($value, $data) {
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

}
